<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="height=device-height,width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<title>连接设备</title>
<style type="text/css">
.bottom_btn_area{
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #8d8d8d;
	width: 100%;
	height: 3rem;
	line-height: 3rem;
	display: block;
	font-size: 0.92rem;
	position: fixed;
	bottom: 0px;
	z-index: 99999;
	background-color: #1e1e1e;
	text-align: center;
}
/*scan_device.html*/
.lineh{
	line-height: 4.57rem;
}
</style>
<link href="img/css/css.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="js/QueryStringParser.js"></script>
<script type="text/javascript" src="js/jquery.json.min.js"></script>  
<script type="text/javascript" src="js/jsonMsg.js"></script>  
</head>

<body>
<div class="check_bar lineh">
      <p>点击下方扫描按钮，扫描周围设备</p>
</div>
<!--list group-->
<a href="#">
<div class="list_group lineh">
     SM-9008s
</div>
</a>
<!--End of list group-->
<!--list group-->
<a href="#">
<div class="list_group lineh">
     SM-9008s
</div>
</a>
<!--End of list group-->
<div class="bottom_btn_area">
     <a href="javascript:void(0);"><button class="ico_group_btn" id="openWXDeviceLib">扫描</button></a>
</div>

	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
	var pageURL = location.href.split('#')[0];
	//alert(pageURL);
	var openId = queryString.getParam("openid");
	$(document).ready(function(){
  	

		var dataStr = {
			PageURL: 	pageURL
		};	
		var bodyStr = popBody('JSSignature',dataStr);
		var request = popRequest('JSSignature',openId,bodyStr);
		//调用了jquery.json 库  
		var encoded = $.toJSON( request );  
		var jsonStr = encoded;  

		$.ajax({  
		url : actionStr,  
		type : 'POST',  
		data : jsonStr,  
		dataType : 'json',  
		contentType : 'application/json',  
		success : function(data, status, xhr) {  
		//         Do Anything After get Return data  
		        var timestamp = data.portalResp.Data.timestamp;
		        var noncestr = data.portalResp.Data.noncestr;
		        var signature = data.portalResp.Data.signature;
		        var appId = data.portalResp.Data.appId;  
		        
		         /*
					   * 注意：
					   * 1. 所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
					   * 2. 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
					   * 3. 常见问题及完整 JS-SDK 文档地址：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
					   *
					   * 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决，如仍未能解决可通过以下渠道反馈：
					   * 邮箱地址：weixin-open@qq.com
					   * 邮件主题：【微信JS-SDK反馈】具体问题
					   * 邮件内容说明：用简明的语言描述问题所在，并交代清楚遇到该问题的场景，可附上截屏图片，微信团队会尽快处理你的反馈。
					   */
					  wx.config({
					  		beta: true, // 开启内测接口调用，注入wx.invoke方法
					      debug: true,
					      appId: appId,
					      timestamp: timestamp,
					      nonceStr: noncestr,
					      signature: signature,
					      jsApiList: [
					      	'hideOptionMenu',
					      	'showOptionMenu',
					        'onMenuShareAppMessage',
					        'openWXDeviceLib',
					        'startScanWXDevice',
					        'getWXDeviceInfos',
					        'onScanWXDevicesResult',
					        'onScanWXDeviceResult',
					        'closeWXDeviceLib',
					        'sendDataToWXDevice',
					        'stopScanWXDevice',
					        'connectWXDevice',
					        'disconnectWXDevice',
					         'getWXDeviceTicket',
					        'configWXDeviceWiFi',
					        'setSendDataDirection'
					      ]
					  });
						
						wx.ready(function () {
							
							var deviceId = "1A32267BA1221988";

	var readyFunc = function onBridgeReady() {
		document.querySelector('#openWXDeviceLib').addEventListener('touchstart', function(e){
			WeixinJSBridge.invoke('openWXDeviceLib', {}, function(res){
				alert(JSON.stringify(res));
				WeixinJSBridge.invoke('startScanWXDevice', {"btVersion": "bc"}, function(res){
				//console.log('startScanWXDevice', res);
				alert(JSON.stringify(res));
			});
			});
		});
//		document.querySelector('#closeWXDeviceLib').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('closeWXDeviceLib', {}, function(res){
//				console.log('closeWXDeviceLib', res);
//			});
//		});
//
//		document.querySelector('#getWXDeviceInfos').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('getWXDeviceInfos', {}, function(res){
//				console.log('getWXDeviceInfos', res);
//			});
//		});
//		document.querySelector('#getWXDeviceBindTicket').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('getWXDeviceTicket', {"deviceId":deviceId, "type":"1"}, function(res){
//				console.log('getWXDeviceTicket', res);
//			});
//		});
//		document.querySelector('#getWXDeviceUnbindTicket').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('getWXDeviceTicket', {"deviceId":deviceId, "type":"2"}, function(res){
//				console.log('getWXDeviceTicket', res);
//			});
//		});
//		document.querySelector('#setSendDataDirection').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('setSendDataDirection', {"deviceId":deviceId, "direction":1 }, function(res){
//				console.log('setSendDataDirection', res);
//			});
//		});
//
//		document.querySelector('#startScanWXDevice').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('startScanWXDevice', {"btVersion": "bc"}, function(res){
//				console.log('startScanWXDevice', res);
//			});
//		});
//		document.querySelector('#stopScanWXDevice').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('stopScanWXDevice', {}, function(res){
//				console.log('stopScanWXDevice', res);
//			});
//		});
//
//		document.querySelector('#connectWXDevice').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('connectWXDevice', {"deviceId":deviceId}, function(res){
//				console.log('connectWXDevice', res);
//			});
//		});
//		document.querySelector('#disconnectWXDevice').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('disconnectWXDevice', {"deviceId":deviceId}, function(res){
//				console.log('disconnectWXDevice', res);
//			});
//		});
//		document.querySelector('#sendDataToWXDevice').addEventListener('touchstart', function(e){
//			WeixinJSBridge.invoke('sendDataToWXDevice', {"deviceId":deviceId, "base64Data":"Ejl="}, function(res){
//				console.log('sendDataToWXDevice', res);
//			});
//		});

		WeixinJSBridge.on('onWXDeviceBindStateChange', function(argv) {
			//console.log('onWXDeviceBindStateChange', argv);
		});
		WeixinJSBridge.on('onWXDeviceStateChange', function(argv) {
			//console.log('onWXDeviceStateChange', argv);
			alert(JSON.stringify(argv));
		});
		WeixinJSBridge.on('onScanWXDeviceResult', function(argv) {
			//console.log('onScanWXDeviceResult', argv);
			alert(JSON.stringify(argv));
			try{
				$.each(argv.devices, function(index){  
            alert(argv.devices[index].deviceId);
        });
    	}catch(e){
    		alert(e);
    	}
		});
		WeixinJSBridge.on('onScanWXDevicesResult', function(argv) {
			//console.log('onScanWXDevicesResult', argv);
			alert(11);
			alert(JSON.stringify(argv));
			alert(22);
			try{
			var str = JSON.stringify(argv);
			alert(33);
			str = str.substring(str.indexOf("deviceId")+11);
			alert(str.substring(0,str.indexOf("\"")));
    }catch(e){
    	alert(e);
    	}
		});
		WeixinJSBridge.on('onReceiveDataFromWXDevice', function(argv) {
			//console.log('onReceiveDataFromWXDevice', argv);
		});
		WeixinJSBridge.on('onWXDeviceBluetoothStateChange', function(argv) {
			//console.log('onWXDeviceBluetoothStateChange', argv);
		});
	};

	if (typeof WeixinJSBridge === "undefined") {
		document.addEventListener('WeixinJSBridgeReady', readyFunc, false);
	} else {
		readyFunc();
	}
							try{	
								wx.hideOptionMenu();
	
								
								
							}catch(e){
								alert(e);
							}
	
						});
					
						wx.error(function (res) {
						  alert(res.errMsg);
						});
					
		},  
		Error : function(xhr, error, exception) {  
		    // handle the error.    
		    alert(exception.toString());  
		}  
		});  
	

 
});

	

	</script>
	
</body>
</html>
